package com.redpack.redpost.struts.action.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.redpack.redpost.struts.form.admin.EditarFolioGuiaForm;
import com.redpack.redpost.util.dao.*;
import com.redpack.redpost.util.to.*;



public class EditarFolioGuiaVal extends Action{
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request, 
			HttpServletResponse response) throws Exception {
		
		
		boolean logginVal = generalUtil.isLoggedInAdmin(request);
		if(logginVal!=true){
			return mapping.findForward("noLogin") ;
		}
		
		
		EditarFolioGuiaForm f = (EditarFolioGuiaForm)form;
		boolean val = false;
		
		if(f != null){
			
			FolioSecuenciaServicioTo _FolioSecuencia = new FolioSecuenciaServicioTo(
					f.getCve_servicio(),
					f.getLimite_inferior(),
					f.getLimite_superior()
					);

			
			val = FolioServicioDao.saveFolioSecuenciaServicio(_FolioSecuencia);
			//Inserta Nueva Secuencia de Guia
			val =  FolioServicioDao.saveFolioSiguiente(_FolioSecuencia.getCve_servicio(),_FolioSecuencia.getLimite_inferior());
			
			if(val)
			{		
				
				request.setAttribute("cve_servicio", ""+_FolioSecuencia.getCve_servicio());
				request.setAttribute("limite_inferior", ""+  _FolioSecuencia.getLimite_inferior());
				request.setAttribute("limite_superior", ""+_FolioSecuencia.getLimite_superior());
				
				request.setAttribute("correcto", ""+val);
			}
			else
			{
				request.setAttribute("cve_servicio", ""+_FolioSecuencia.getCve_servicio());
				request.setAttribute("limite_inferior", ""+  _FolioSecuencia.getLimite_inferior());
				request.setAttribute("limite_superior", ""+_FolioSecuencia.getLimite_superior());
				
				request.setAttribute("correcto", ""+val);
				
			}
			
			return mapping.findForward("successEdit") ;
		
		}
		return mapping.findForward("successEdit") ;	
	}

		// TODO Auto-generated method stub
}
